﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yugi.Client.Card;
using Yugi.Client.Card.FileDecoder;
namespace Yugi.Client.Converter
{
    partial class ConvertData
    {
        //-----------------NormalSummon 1----------------------------//
        private void ConvertData_CARD_LENBAI_HOPLE(byte[] input)
        {
           
            int card_id = (int)input[0];
            int mess = (int)input[1];
            Result.Add(card_id);
            Result.Add(mess);
         
        }
        private void ConvertData_CARD_LENBAI_KHONGHOPLE(byte[] input)
        {

            string error = ASCIIEncoding.UTF8.GetString(input);

            Result.Add(error);

        }
        private void ConvertData_CARD_LENBAI_XONG(byte[] input)
        {

            //int card_type = (int)input[0];
            //int card_id = (int)input[1];
            int card_type = DecodeInt(ref input);
            int card_id = DecodeByte(ref input);
            YBaseCard card = GetCard(card_type);
            card.ID = card_id;
            Result.Add(card);

            //int x = (int)input[2];
            //int y = (int)input[3];
            //int mess = (int)input[4];

            int x = (int)input[0];
            int y = (int)input[1];
            int mess = (int)input[2];

            Result.Add(x);
            Result.Add(y);
            Result.Add(mess);
        }
        //------------------------------Change Position----------------------//
        private void ConvertData_CARD_DOITRANGTHAI_XONG(byte[] input)
        {

            int card_id = (int)input[0];
            int mess = (int)input[1];
            Result.Add(card_id);
            Result.Add(mess);

        }
        //------------------------------Normal Summon 2----------------------//
        private void ConvertData_CARD_LENBAI_SUMMONDACBIET_HOPLE(byte[] input)
        {
           
            int card_id = (int)input[0];
            
            Result.Add(card_id);
            //int soluong = (int)input[1];
            //int i;
            //for (i = 0; i <= soluong+1; i++)
            //{
            //    Result.Add((int)input[i]);
            //}
            //int x = (int)input[i];
            //int y = (int)input[i + 1];
            //int mess = (int)input[i + 2];
            //Result.Add(x);
            //Result.Add(y);
            //Result.Add(mess);
         
        }
        private void ConvertData_CARD_LENBAI_SUMMONDACBIET_KHONGHOPLE(byte[] input)
        {

            string error = ASCIIEncoding.UTF8.GetString(input);

            Result.Add(error);


        }
         private void ConvertData_CARD_LENBAI_SUMMONDACBIET_XONG(byte[] input)
        {
           
            //int type_id = (int)input[0];
            //int card_id = (int)input[1];
            int type_id = DecodeInt(ref input);
            int card_id = DecodeByte(ref input);
            

            YBaseCard new_card= GetCard(type_id);
            new_card.ID = card_id;
            Result.Add(new_card);
            
            //int soluong = (int)input[2];
            //Result.Add(soluong);
            //int i;
            //for (i = 3; i <= soluong+2; i++)
            //{
            //     Result.Add((int)input[i]);
            //}
            //int x = 4-(int)input[i];
            //int y = 6-(int)input[i+1];
            //int mess = (int)input[i+2];

            int soluong = DecodeByte(ref input);
            Result.Add(soluong);
            for (int i = 0; i < soluong; i++)
            {
                Result.Add(DecodeByte(ref input));
            }
            int x = 4 - DecodeByte(ref input);
            int y = 6 - DecodeByte(ref input);
            int mess =  DecodeByte(ref input);
            Result.Add(x);
            Result.Add(y);
            Result.Add(mess);
         
        }
        //------------Spell-----------//
         private void ConvertData_CARD_LENBAI_SPELL_HOPLE(byte[] input)
         {
             int card_id = (int)input[0];
             Result.Add(card_id);
             Result.Add((Common.YMSG) input[1]);
         }
         private void ConvertData_CARD_LENBAI_SPELL_KHONGHOPLE(byte[] input)
         {

             string error = ASCIIEncoding.UTF8.GetString(input);

             Result.Add(error);
         }
         private void ConvertData_CARD_LENBAI_SPELL_XONG(byte[] input)
         {

             //int card_type = (int)input[0];
             //int card_id = (int)input[1];
             int card_type = DecodeInt(ref input);
             int card_id = DecodeByte(ref input);

             YBaseCard card = GetCard(card_type);
             card.ID = card_id;
             Result.Add(card);

             //int x = (int)input[2];
             //int y = (int)input[3];
             //int mess = (int)input[4];

             int x = (int)input[0];
             int y = (int)input[1];
             int mess = (int)input[2];

             Result.Add(x);
             Result.Add(y);
             Result.Add(mess);
         }
         //------------Trap-----------//
         private void ConvertData_CARD_LENBAI_TRAP_HOPLE(byte[] input)
         {
             int card_id = (int)input[0];
             Result.Add(card_id);
             Result.Add((Common.YMSG)input[1]);
         }
         private void ConvertData_CARD_LENBAI_TRAP_KHONGHOPLE(byte[] input)
         {

             string error = ASCIIEncoding.UTF8.GetString(input);

             Result.Add(error);
         }
         private void ConvertData_CARD_LENBAI_TRAP_XONG(byte[] input)
         {

             //int card_type = (int)input[0];
             //int card_id = (int)input[1];
             int card_type = DecodeInt(ref input);
             int card_id = DecodeByte(ref input);

             YBaseCard card = GetCard(card_type);
             card.ID = card_id;
             Result.Add(card);

             //int x = (int)input[2];
             //int y = (int)input[3];
             //int mess = (int)input[4];

             int x = (int)input[0];
             int y = (int)input[1];
             int mess = (int)input[2];

             Result.Add(x);
             Result.Add(y);
             Result.Add(mess);
         }
        ////////////////////////////////////////////////////////////////
        //----------------------------Send----------------------------//
        ////////////////////////////////////////////////////////////////
        //---------------------------Normal Summon------------------------//
        private void ConvertSendData_CARD_LENBAI(object[] input)
        {
            byte id = (byte)(int)((YBaseCard)input[0]).ID;
            byte mess = (byte)(int)input[1];
            Result_Send.Add(id);
            Result_Send.Add(mess);
            
        }
       
        private void ConvertSendData_CARD_LENBAI_XONG(object[] input)
        {
            YBaseCard card = input[0] as YBaseCard;
            byte x = (byte)(int)input[1];
            byte y = (byte)(int)input[2];
            byte mess = (byte)(int)input[3];

            //Result_Send.Add((byte)(int)card.Card_TypeID);
            Result_Send.AddRange(BitConverter.GetBytes(card.Card_TypeID));
            Result_Send.Add((byte)(int)card.ID);
            Result_Send.Add(x);
            Result_Send.Add(y);
            Result_Send.Add(mess);
            
        }

       
        private void ConvertSendData_CARD_LENBAI_SUMMONDACBIET(object[] input)
        {
            foreach (int item in input)
            {
                Result_Send.Add((byte)item);
            }

        }
        //----------------------Change Position-------------------------//
        private void ConvertSendData_CARD_DOITRANGTHAI(object[] input)
        {
            YBaseCard card = input[0] as YBaseCard;
            byte mess = (byte)(int)input[1];
            Result_Send.Add((byte)(int)card.ID);
            Result_Send.Add(mess);
        }

        //--------------Spell---------------
        private void ConvertSendData_CARD_LENBAI_SPELL(object[] input)
        {
            byte id = (byte)(int)((YBaseCard)input[0]).ID;
            byte mess = (byte)(int)input[1];
            Result_Send.Add(id);
            Result_Send.Add(mess);

        }
        private void ConvertSendData_CARD_LENBAI_SPELL_XONG(object[] input)
        {
            YBaseCard card = input[0] as YBaseCard;
            byte x = (byte)(int)input[1];
            byte y = (byte)(int)input[2];
            byte mess = (byte)(int)input[3];

            //Result_Send.Add((byte)(int)card.Card_TypeID);
            Result_Send.AddRange(BitConverter.GetBytes(card.Card_TypeID));
            Result_Send.Add((byte)(int)card.ID);
            Result_Send.Add(x);
            Result_Send.Add(y);
            Result_Send.Add(mess);

        }

        //--------------Trap---------------
        private void ConvertSendData_CARD_LENBAI_TRAP(object[] input)
        {
            byte id = (byte)(int)((YBaseCard)input[0]).ID;
            byte mess = (byte)(int)input[1];
            Result_Send.Add(id);
            Result_Send.Add(mess);

        }
        private void ConvertSendData_CARD_LENBAI_TRAP_XONG(object[] input)
        {
            YBaseCard card = input[0] as YBaseCard;
            byte x = (byte)(int)input[1];
            byte y = (byte)(int)input[2];
            byte mess = (byte)(int)input[3];

            //Result_Send.Add((byte)(int)card.Card_TypeID);
            Result_Send.AddRange(BitConverter.GetBytes(card.Card_TypeID));
            Result_Send.Add((byte)(int)card.ID);
            Result_Send.Add(x);
            Result_Send.Add(y);
            Result_Send.Add(mess);

        }
    }
}
